<?php
/**
 * 设置考评员工
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Jx_Setting");
apf_require_class("Util_ApioAuth");
class Ajax_ChangeMemberController extends AbstractController {

    public function handle_request() {
        $params=APF::get_instance()->get_request()->get_parameters();
        $bll=new Bll_Jx_Setting();
        if($params['code_under'] && $params["under"]=="under"){
        $underling=$bll->get_member_by_code($params['code_under']);
        if(!$underling){
          $info=Util_ApioAuth::get_user_info_by_api($params['code_under']);
        if($info!='[]'){
          $this->json_encode(1,json_decode($info));
        }
         else 
          $this->json_encode(1,"none");
        }
        else 
          $this->json_encode(1, $underling);
        }
        if($params['code_superior'] && $params["super"]=="super"){
         $super=$bll->get_member_by_code($params['code_superior']);
          if(!$super){
           $info=Util_ApioAuth::get_user_info_by_api($params['code_superior']);
            if($info!='[]'){
             $this->json_encode(1,json_decode($info));
           }else 
            $this->json_encode(1,"none");
          }
          else 
            $this->json_encode(1,$super);
       }
           if($params['id_underling'] && $params['id_superior']){
           $user=$bll->get_member_by_code($params['id_underling']);
            /*
             * set_change_member_superior($param1,$param2);
             * $param1 :super,$param2 :under
             */
               if(empty($user)){
               $info=Util_ApioAuth::get_user_department_id($params['id_underling']);
               $u=json_decode($info);
               $uu=(array)$u[0];
               $bll->insert_into_kp_table($uu['user_id'],$uu['name'],$uu['code'],$uu['superior_code'],$uu['enter_date'],
               $uu['department_id']);
                             }
            $stat_1=$bll->set_change_member_superior($params['id_superior'],$params['id_underling']);
            $stat_2=$bll->set_change_member_superior($user[0]["superior_code"],$params['id_superior']);
            if($stat_1 && $stat_2)
            $this->json_encode(1, "success");
            else 
            $this->json_encode(0, "fail");
      }
    }
}